package itheima.com.Day13.Test6;

public class MyThread extends Thread {
    private static int tickets = 100;
    private static Object lock = new Object();

    @Override
    public void run() {
        while (true) {
            synchronized (lock) {
                if (tickets <= 0) {
                    break;
                } else {
                    try {
                        Thread.sleep(10);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    tickets--;
                    System.out.println(Thread.currentThread().getName() + "还剩" + tickets + "张票在出售");
                }
            }
        }
    }
}
